﻿#region Imports
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
#endregion

namespace OneStopProgrammingMatrix.Converters
{
    public class VisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool source = (bool)value;
            string option = parameter as string;
            Visibility result;

            if (option.StartsWith("-")) source = !source;

            if (source) result = Visibility.Visible;
            else result = (option.Trim('-') == "H") ? Visibility.Hidden : Visibility.Collapsed;

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Visibility source = (Visibility)value;
            string option = parameter as string;

            bool result = (source == Visibility.Visible);
            if (option.StartsWith("-")) result = !result;

            return result;
        }
    }
}
